package com.xxx.util;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;

import com.xxx.listener.SystemListener;

public class FileUtil {
	
	/**
	 * 从工程某一目录下读取文件内容到字符串里
	 */
	public static String readFileToStr (String filePath, String fileName) {
		String result = "";
		String basePath = "";
		if(CommonUtil.isWin()) {
			basePath = RSAUtil.class.getResource(filePath).getPath();// 本地debug用
			if(basePath.startsWith("/")) {
				basePath = basePath.substring(1);
			}
		} else if (CommonUtil.isLinux()) {
			basePath = SystemListener.realPath + "/WEB-INF/classes"+filePath;
		}
		String fileAbsPath = Escape.unescape(basePath + fileName);
        try {
        	result = FileUtils.readFileToString(new File(fileAbsPath), "UTF-8");
		} catch (IOException e1) {
			e1.printStackTrace();
		}
        return result;
	}

}
